package com.hcb.micro.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hcb.micro.dao.interfaceClass.CityMapper;
import com.hcb.micro.dao.interfaceClass.DistrictMapper;
import com.hcb.micro.dao.interfaceClass.OrderReceiveAddressMapper;
import com.hcb.micro.dao.interfaceClass.ProvinceMapper;
import com.hcb.micro.dto.City;
import com.hcb.micro.dto.District;
import com.hcb.micro.dto.OrderReceiveAddress;
import com.hcb.micro.dto.Province;
import com.hcb.micro.service.IOrderReceiveAddressService;

@Service("OrderReceiveAddressService")
public class OrderReceiveAddressServiceImpl implements IOrderReceiveAddressService {

	@Autowired
	OrderReceiveAddressMapper orderReceiveAddressMapper;
	
	@Autowired
	DistrictMapper districtMapper;
	
	@Autowired
	CityMapper cityMapper;
	
	@Autowired
	ProvinceMapper provinceMapper;
	
	@Override
	public int deleteByPrimaryKey(Integer id) {
		return orderReceiveAddressMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(OrderReceiveAddress record) {
		return orderReceiveAddressMapper.insert(record);
	}

	@Override
	public int insertSelective(OrderReceiveAddress record) {
		return orderReceiveAddressMapper.insertSelective(record);
	}

	@Override
	public OrderReceiveAddress selectByPrimaryKey(Integer id) {
		return orderReceiveAddressMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(OrderReceiveAddress record) {
		return orderReceiveAddressMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(OrderReceiveAddress record) {
		return orderReceiveAddressMapper.updateByPrimaryKey(record);
	}

	@Override
	public Map<String, Object> getOrderAddressDetail(Integer id) {
		
		OrderReceiveAddress orderReceiveAddress = orderReceiveAddressMapper.selectByPrimaryKey(id);
		
		Province province = provinceMapper.selectByProvinceId(Integer.valueOf(orderReceiveAddress.getProvince()));
		
		City city = cityMapper.selectByCityId(Integer.valueOf(orderReceiveAddress.getCity()));
		
		District district = districtMapper.selectByDistrictId(Integer.valueOf(orderReceiveAddress.getDistrict()));
		
		Map<String,Object> address = new HashMap<>();
		address.put("fullName", orderReceiveAddress.getFullName());
		address.put("mobileNumber", orderReceiveAddress.getMobileNumber());
		address.put("detailAddress", orderReceiveAddress.getDetailAddress());
		address.put("address", province.getName()+city.getName()+district.getName()+orderReceiveAddress.getDetailAddress());
		return address;
	}

}
